package com.th.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.th.common.domain.*;
import com.th.config.web.BaseController;
import com.th.service.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author tuhang
 * @PackageName nswcy-crowdsource-client-server
 * @Package com.th.controller
 * @Date 2023/6/7 22:17
 * @Version 1.0
 */
@RestController
@Api(tags = "元数据接口")
@RequestMapping("/api/metadata")
public class MetadataController extends BaseController {

    @Resource
    private MetadataBankService metadataBankService;
    @Resource
    private MetadataCadCityService metadataCadCityService;
    @Resource
    private MetadataCadCountyService metadataCadCountyService;
    @Resource
    private MetadataCadProvinceService metadataCadProvinceService;
    @Resource
    private MetadataDomainService metadataDomainService;
    @Resource
    private MetadataEnterpriseMainBusinessTypeService metadataEnterpriseMainBusinessTypeService;
    @Resource
    private MetadataStyleService metadataStyleService;
    @Resource
    private MetadataTypeService metadataTypeService;
    @Resource
    private MetadataUniversityService metadataUniversityService;



    /**
     * 查询银行列表
     */
    @GetMapping("/bank/list")
    public List<MetadataBank> bankList() {
        return metadataBankService.list();
    }

    /**
     * 查询领域列表
     */
    @GetMapping("/domain/list")
    public List<MetadataDomain> domainList() {
        return metadataDomainService.list();
    }


    /**
     * 查询企业主营业务品类列表
     */
    @GetMapping("/enterprise-main-business-type/list")
    public List<MetadataEnterpriseMainBusinessType> businessTypeList() {
        QueryWrapper<MetadataEnterpriseMainBusinessType> queryWrapper = new QueryWrapper<MetadataEnterpriseMainBusinessType>().orderByAsc("order_num");
         return metadataEnterpriseMainBusinessTypeService.list(queryWrapper);
    }


    /**
     * 查询风格列表
     */
    @GetMapping("/style/list")
    public List<MetadataStyle> styleList() {
        QueryWrapper<MetadataStyle> queryWrapper = new QueryWrapper<MetadataStyle>().orderByAsc("order_num");
        List<MetadataStyle> list = metadataStyleService.list(queryWrapper);
        return metadataStyleService.list(queryWrapper);
    }

    /**
     * 查询类型列表
     */
    @GetMapping("/type/list")
    public List<MetadataType> typeList() {
        return metadataTypeService.list();
    }


    /**
     * 查询学校列表
     */
    @GetMapping("/university/list")
    public List<MetadataUniversity> universityList() {
        return metadataUniversityService.list();
    }

    /**
     * 通过省号查询市
     * @param provinceId
     * @return
     */
    @ApiOperation("通过省号查询市")
    @GetMapping("/city/list")
    public List<MetadataCadCity> cityList(String provinceId) {
        QueryWrapper<MetadataCadCity> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("province_id", provinceId);
        return metadataCadCityService.list(queryWrapper);
    }

    /**
     * 查询所有省
     * @return
     */
    @ApiOperation("查询所有省")
    @GetMapping("/province/list")
    public List<MetadataCadProvince> provinceList() {
        return metadataCadProvinceService.list();
    }

    @ApiOperation("通过市号查询区县")
    @GetMapping("/county/list")
    public List<MetadataCadCounty> countyList(String cityId) {
        QueryWrapper<MetadataCadCounty> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("city_id", cityId);
        return metadataCadCountyService.list(queryWrapper);
    }
}
